package com.sanjiahantang.youjiaclient.module.me.require.views.impl;

import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.sanjiahantang.uilibrary.adapter.listview.BaseAdapterHelper;
import com.sanjiahantang.uilibrary.adapter.listview.QuickAdapter;
import com.sanjiahantang.uilibrary.utils.Utils;
import com.sanjiahantang.youjiaclient.R;
import com.sanjiahantang.youjiaclient.base.BaseApplication;
import com.sanjiahantang.youjiaclient.base.BaseMvpActivity;
import com.sanjiahantang.youjiaclient.config.ConfigValue;
import com.sanjiahantang.youjiaclient.module.cases.views.impl.DesignerDetailActivity;
import com.sanjiahantang.youjiaclient.module.me.require.beans.BidDesignerBean;
import com.sanjiahantang.youjiaclient.module.me.require.presenters.RequirePresenter;
import com.sanjiahantang.youjiaclient.module.me.require.views.RequireView;
import com.sanjiahantang.youjiaclient.utils.FileUtils;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by zy on 2017/12/28.
 */

public class BidListActivity extends BaseMvpActivity<RequireView,RequirePresenter> implements RequireView, View.OnClickListener {


    private int requireId;
    private ListView listView;
    private QuickAdapter<BidDesignerBean.Data> adapter;

    @Override
    public void showProgress() {
        super.showProgress($this);
    }

    @Override
    public RequirePresenter initPresenter() {
        return new RequirePresenter();
    }

    @Override
    public void initView() {
        setContentView(R.layout.activity_common_list);
        TextView title = (TextView) findViewById(R.id.title);
        title.setText("设计师列表");
        findViewById(R.id.fl_Left).setOnClickListener(this);
        listView = (ListView) findViewById(R.id.listView);
        adapter = new QuickAdapter<BidDesignerBean.Data>($this,R.layout.item_designer) {
            @Override
            protected void convert(BaseAdapterHelper helper, final BidDesignerBean.Data item) {
                helper.setText(R.id.name,item.getUserName());
                helper.setText(R.id.txtRate,item.getSysPoints() + "评分");
                helper.setText(R.id.time,"签约 " + String.valueOf((item.getToDay() / 365) + 1) + "年");
                helper.setText(R.id.txtCity,item.getAddress());
                ImageView iv_image = helper.getView(R.id.iv_image);
                Picasso.with(context).load(FileUtils.rePath(item.getUrl())).placeholder(R.drawable.i_head_default).into(iv_image);
                helper.getView().setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        startActivity(new Intent($this, DesignerDetailActivity.class)
                                .putExtra(KEY_PHONE, item.getRoleId())
                                .putExtra("isBid",requireId)
                        );

                        BaseApplication.addActivity($this);
                    }
                });
            }
        };
        listView.setAdapter(adapter);
        requireId = getIntent().getIntExtra(KEY_ID,-1);
        if (requireId == -1){
            Utils.showToast($this,"无效需求单");
            finish();
            return;
        }
    }

    @Override
    public void initData() {

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.fl_Left:
                finish();
                break;
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        presenter.findRequireBidInfoForCustomer($this,requireId, new OnLoadListener() {
            @Override
            public void onLoad(Object content) {
                if (content != null && content instanceof List){
                    List<BidDesignerBean.Data> data = (List<BidDesignerBean.Data>) content;
                    adapter.clear();
                    adapter.addAll(data);
                }
            }
        });
    }
}
